<template>
  <JwChat-index
  	 :config ="config"
     :taleList="list"
     @enter="bindEnter"
     v-model="inputMsg"
     :scrollType = "scrollType"
     :toolConfig="tool"
 >
  <JwChat-rightbox :config="rightConfig" @click="rightClick" />

 </JwChat-index>

</template>

<script>
import { compareTEXT } from "../util/tools.js"
export default {
  name: 'HelloWorld',
  data () {
    return {
    	config: {
        img: '../static/image/men.png',
        name: '机器人-小智',
        dept: '',
        callback: this.bindCover
      },
      list: [
      	{
          "date": "",
          "text": { "text": "你好，这里是防骗模拟智能机器人小智。" },
          "mine": false,
          "name": "智能机器人-小智",
          "img": "../static/image/men.png"
       }
      ],
      inputMsg: '',
      tool: {
      	// 现在只配置了 ["file", "video", "img", "hongbao", "more", "history"]
      	show: ['history','img','file','hongbao'],
    		callback: this.toolEvent,
    		showEmoji: true,
      },
      scrollType: 'scroll' ,
      rightConfig: {
      	tip: '公告',
        listTip: '当前在线',
         notice: '防骗智能机器人小智带你模拟真实诈骗对话经过!',
        list: [
          {
            name: '我',
            "img": "../static/image/women.png"
          },
          {
            name: '智能机器人-小智',
            "img": "../static/image/men.png"
          },
       {
         name: '只盼流星不盼雨',
         "img": "../static/image/men.png"
       }
        ]
      }
    }
  },
  methods: {
    bindEnter () {
      const msg = this.inputMsg
      if (!msg) return;
      
      
      var msgObj = {
        "date": "",
        "text": { "text": msg },
        //通过mine字段来控制是本人发还是对方发
        "mine": true,
        "name": "JwChat",
        "img": "../static/image/men.png"
      }
      this.list.push(msgObj)
      //回复
      this.keyWordsMate(msg)
    },
    toolEvent (type) {
      //console.log('tools', type)
    },
    rightClick (type) {
      console.log('rigth', type)
    },

  //语句匹配
  keyWordsMate(data){
    //调用方法
    let result = compareTEXT(data)
    this.sleep1(result)
  },
  //发送
  responseMsg(data){
         //回复语句在此输入
      var msgObj = {
        "date": "",
        "text": { "text": data},
        //通过mine字段来控制是本人发还是对方发
        "mine": false,
        "name": "智能机器人-小智",
        "img": "../static/image/men.png"
      }
      this.list.push(msgObj)
      this.config.name = "机器人-小智"
  },


  //随机等待 显示正在输入
  sleep1(data){
    let that = this
    var randomTime1 = Math.ceil(Math.random()*3000); 
    setTimeout(function(){
      that.config.name = "机器人-小智(正在输入中...)";
      that.test2(data)
      },randomTime1);
    },

//随机等待 回消息
  test2(data){
    let that = this
    var randomTime2 = Math.ceil(Math.random()*10000); 
    setTimeout(function(){
      that.responseMsg(data)
      },randomTime2);
  }
  }
}
</script>
<style scoped>
</style>
